﻿<html DIR="LTR" xmlns:tool="http://www.microsoft.com/tooltip" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:ddue="http://ddue.schemas.microsoft.com/authoring/2003/5" xmlns:MSHelp="http://msdn.microsoft.com/mshelp">
  <head>
    <META HTTP-EQUIV="Content-Type" CONTENT="text/html; CHARSET=utf-8" />
    <META NAME="save" CONTENT="history" />
    <title>Using Database Metadata</title>
    
    <link rel="stylesheet" type="text/css" href="../local/Classic.css">
      
    </link>
    
    <script src="../local/script.js">
      
    </script><script src="../local/script_main.js">&amp;nbsp;</script>
  </head>
  <body>
    <!--Topic built:03/05/2009 21:01:45-->

    
    
    
    
    
    
    
    
    
    <div id="header">
      <table width="100%" id="topTable"><tr>
          <td align="left">
            <span id="headerBold">Using Database Metadata</span>
          </td>
          <td align="right">
            
          </td>
        </tr></table>
      
      
      
    </div>
    <div id="mainSection">
      
        
        
		<font color="DarkGray"> </font> <p /> <p />
	
        <div id="introductionSection" class="section">
    <p>To query a database for information about what it supports, the Microsoft SQL Server JDBC Driver implements the <a href="8b8049d0-8c6d-4476-866b-098709f37eec.htm">SQLServerDatabaseMetaData</a> class. This class contains numerous methods that return information in the form of a single value, or as a result set. </p>
    <p>To create a <b>SQLServerDatabaseMetaData</b> object, you can use the <a href="86223cb5-3bf4-489a-8c82-669a91764f2b.htm">getMetaData</a> method of the <a href="937292a6-1525-423e-a2b2-a18fd34c2893.htm">SQLServerConnection</a> class to get information about the database that it is connected to.</p>
    <p>In the following example, an open connection to the SQL Server 2005 AdventureWorks sample database is passed in to the function, the <b>getMetaData</b> method of the <b>SQLServerConnection</b> class is used to return a <b>SQLServerDatabaseMetadata</b> object, and then various methods of the <b>SQLServerDatabaseMetaData</b> object are used to display information about the driver, driver version, database name, and database version.</p>
    <div class="sampleCode"><span codeLanguage="other"><pre>public static void getDatabaseMetaData(Connection con) {
   try {
      DatabaseMetaData dbmd = con.getMetaData();
      System.out.println("dbmd:driver version = " + dbmd.getDriverVersion());
      System.out.println("dbmd:driver name = " + dbmd.getDriverName());
      System.out.println("db name = " + dbmd.getDatabaseProductName());
      System.out.println("db ver = " + dbmd.getDatabaseProductVersion());
   }
   catch (Exception e) {
      e.printStackTrace();
   }
}
</pre></span></div>
  </div><span id="seeAlsoSpan"><h1 class="heading">See Also</h1></span><div id="seeAlsoSection" class="section" name="collapseableSection"><a href="5cfb35d4-ddcd-40a2-8091-f29cddc32552.htm">Handling Metadata with the JDBC Driver</a><br /><br /></div><!--[if gte IE 5]>
			<tool:tip element="seeAlsoToolTip" avoidmouse="false"/><tool:tip element="languageFilterToolTip" avoidmouse="false"/><tool:tip element="roleInfoSpan" avoidmouse="false"/>
		<![endif]-->
      <div id="footer" class="section">
        
		<hr />
		
		<span id="fb" class="feedbackcss">
			
			
		</span>
		
		<a href="9bad553b-9e70-4696-8499-2e35f772a1e0.htm">
			
			© 2009 Microsoft Corporation. All rights reserved.
		</a>
 	
	
      </div>
    </div>
  </body>
</html>